package example.org;

import java.io.FileNotFoundException;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class EditImage extends Activity implements OnClickListener {
	private Button mOk;
	private String lemparan;
	private Uri imageFileUri;
	private ImageView chosenImageView;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.editpicture);

		chosenImageView = (ImageView) findViewById(R.id.imageView1);
		mOk = (Button) findViewById(R.id.button1);
		mOk.setOnClickListener(this);
		Bundle extrax = getIntent().getExtras();
		if (extrax != null) {
			lemparan = extrax.getString("gambar");
		}

		// Toast.makeText(this, imageFileUri, Toast.LENGTH_SHORT).show();
		// load
		// Display currentDisplay = getWindowManager().getDefaultDisplay();
		// int dw = currentDisplay.getWidth();
		// int dh = currentDisplay.getHeight() / 2 - 100;

		try {
			imageFileUri = Uri.parse(lemparan);
			BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
			bmpFactoryOptions.inJustDecodeBounds = true;
			Bitmap bmp = BitmapFactory.decodeStream(getContentResolver()
					.openInputStream(imageFileUri), null, bmpFactoryOptions);
			bmpFactoryOptions.inSampleSize = 2;
			bmpFactoryOptions.inJustDecodeBounds = false;
			bmp = BitmapFactory.decodeStream(getContentResolver()
					.openInputStream(imageFileUri), null, bmpFactoryOptions);
			chosenImageView.setImageBitmap(bmp);
		} catch (FileNotFoundException e) {
			Log.v("ERROR", e.toString());
		}

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v == mOk) {
			 Intent i = new Intent(this, ShareVia.class);
			 i.putExtra("gambar", imageFileUri + "");
			 startActivity(i);
		}
	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (resultCode == Activity.RESULT_OK) {
			this.finish();
		}
	}
}
